<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import userBag from '@/api/user/userBag'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  userBag.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  userBag.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'user_bag',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: userBag.getList,
  recycleApi: userBag.getRecycleList,
  add: {
    show: true,
    api: userBag.save,
    auth: ['user:bag:save']
  },
  edit: {
    show: true,
    api: userBag.update,
    auth: ['user:bag:update']
  },
  delete: {
    show: true,
    api: userBag.deletes,
    auth: ['user:bag:delete'],
    realApi: userBag.realDeletes,
    realAuth: ['user:bag:realDeletes']
  },
  recovery: {
    show: true,
    api: userBag.recoverys,
    auth: ['user:bag:recovery']
  },
  import: {
    show: true,
    url: 'user/bag/import',
    templateUrl: 'user/bag/downloadTemplate',
    auth: ['user:bag:import']
  },
  export: {
    show: true,
    url: 'user/bag/export',
    auth: ['user:bag:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "用户id",
    dataIndex: "user_id",
    formType: "input"
  },
  {
    title: "产品id",
    dataIndex: "product_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "产品名称",
    dataIndex: "product_name",
    formType: "input",
    search: true
  },
  {
    title: "产品价格",
    dataIndex: "price",
    formType: "input"
  },
  {
    title: "产品图片",
    dataIndex: "product_img",
    formType: "input"
  },
  {
    title: "扩展字段",
    dataIndex: "extend_field",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "背包产品来源",
    dataIndex: "source_type",
    formType: "input",
    search: true
  },
  {
    title: "来源对应id",
    dataIndex: "source_id",
    formType: "input",
    search: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    search: true
  },
  {
    title: "dtm事务",
    dataIndex: "gid",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'user:bag' } </script>